import { create_ListenEvent_mana } from '../../../../../../global/element/Event/listenEvent_mana';
import { normalizeContainer } from '../../../../../../global/element/Func';
import { setToCurEl_keyVal_node } from '../../Func/setToCurEl_keyVal_node';
import {
  unf_spantag_keyVal,
  uni_ns_form_span_tag_inp_hasVal,
} from './DataDefine/sourceData';

/**
 * 浮动元素 的 标签名 inp id
 */
const tag_inp_id = 'keyVal_input-span_tag';

/**
 * 浮动元素 的 标签名 inp El
 * @type {HTMLElement}
 */
let tag_inp_el;

let eventM = create_ListenEvent_mana('uni_ns_form_spantag');

/**
 * 初始化 浮动元素 的 tag
 */
function init_unfs() {
  tag_inp_el = normalizeContainer(tag_inp_id);

  eventM.addEventListen(tag_inp_el, 'blur', tag_inp_blur);
}

/**
 * 当 浮动元素 的 标签名 inp 失焦时 触发 记录值
 * @param {MouseEvent} event
 */
function tag_inp_blur(event) {
  /**
   * @type {HTMLInputElement}
   */
  let targetEl = event.currentTarget;

  let val = targetEl.value;
  // console.log(val != '');
  tag_inp_el.setAttribute(uni_ns_form_span_tag_inp_hasVal, val != '');

  setToCurEl_keyVal_node(unf_spantag_keyVal, val);
}

export { init_unfs };
